package cn.hist.hfp.repository;

import cn.hist.hfp.entity.Pet;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface PetRepository extends JpaRepository<Pet, Integer>{

    @Query("select p from Pet p where (select count(o) from PetOrder o where o.pet = p) = 0 and p.species.name = :name")
    Page<Pet> findAllBySpeciesName(@Param("name") String name, Pageable pageable);

    @Query("select p from Pet p where (select count(o) from PetOrder o where o.pet = p) = 0")
    Page<Pet> findAll(Pageable pageable);
}
